package com.fyl.imports;

import com.fyl.beans.OtherBean2;
import com.fyl.config.SpringConfig;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.MultiValueMap;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;

public class MyImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        //参数AnnotationMetadata 元注解，该对象内部封装是当前使用了@Import注解类上的其他注解
        Map<String, Object> allAnnotationAttributes = annotationMetadata.getAllAnnotationAttributes(ComponentScan.class.getName()).toSingleValueMap();
        allAnnotationAttributes.forEach((k,v)->
                System.out.println(k+"=="+v.toString()));
        String[] value = (String[]) allAnnotationAttributes.get("value");
        System.out.println(value[0]);
        System.out.println("value = " + value);
        //返回的数组封装的是需要注册到spring容器中的bean的全限定类名
        return new String[] {OtherBean2.class.getName()};
        //return new String[0];
    }


}
